/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-08 10:41:50
 * @LastEditTime: 2022-03-03 17:56:19
 * @LastEditors: 赵大壮
 */

export enum nyNetErrorType {
    success,
    networkError,
    timeout,
    permissionError,
    tokenExpire,
    tokenInvaild,
    other,
}

export class nyNetError {
    error(errorType: nyNetErrorType, response: any) {
        switch (errorType) {
            case nyNetErrorType.success:
                console.log('success');
                break;
            case nyNetErrorType.networkError: 
                console.log('networkError');
                break;
            case nyNetErrorType.timeout:
                console.log('timeout');
                break;
            case nyNetErrorType.permissionError:
                console.log('permissionError');
                break;
            case nyNetErrorType.tokenExpire:
                console.log('tokenExpire');
                break;
            case nyNetErrorType.tokenInvaild:
                console.log('tokenInvaild');
                break;
            case nyNetErrorType.other:
                console.log('other');
                break;
            default:
                break;
        }
    }

    customErrorCode(code: string, response: any) {
        var result = errorJson[code] != undefined ? errorJson[code] : nyNetErrorType.other;
        
        this.error(result, response);
    }
}

var errorJson: { [key: string]: nyNetErrorType } = {
    '200': nyNetErrorType.success,
    '500': nyNetErrorType.networkError,
    '300': nyNetErrorType.timeout,
    '201': nyNetErrorType.tokenExpire,
    '2023': nyNetErrorType.tokenExpire,
}